home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / lib / sunbird / components / calItemModule.js < prev    next >
Encoding:
Text File  |  2007-05-23  |  11.4 KB  |  299 lines

  1. /* -*- Mode: javascript; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4.  *
  5.  * The contents of this file are subject to the Mozilla Public License Version
  6.  * 1.1 (the "License"); you may not use this file except in compliance with
  7.  * the License. You may obtain a copy of the License at
  8.  * http://www.mozilla.org/MPL/
  9.  *
  10.  * Software distributed under the License is distributed on an "AS IS" basis,
  11.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12.  * for the specific language governing rights and limitations under the
  13.  * License.
  14.  *
  15.  * The Original Code is Oracle Corporation code.
  16.  *
  17.  * The Initial Developer of the Original Code is
  18.  *  Oracle Corporation
  19.  * Portions created by the Initial Developer are Copyright (C) 2004
  20.  * the Initial Developer. All Rights Reserved.
  21.  *
  22.  * Contributor(s):
  23.  *   Vladimir Vukicevic <vladimir.vukicevic@oracle.com>
  24.  *   Mike Shaver <shaver@off.net>
  25.  *   Matthew Willis <lilmatt@mozilla.com>
  26.  *   Philipp Kewisch <mozilla@kewis.ch>
  27.  *
  28.  * Alternatively, the contents of this file may be used under the terms of
  29.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  30.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  31.  * in which case the provisions of the GPL or the LGPL are applicable instead
  32.  * of those above. If you wish to allow use of your version of this file only
  33.  * under the terms of either the GPL or the LGPL, and not to allow others to
  34.  * use your version of this file under the terms of the MPL, indicate your
  35.  * decision by deleting the provisions above and replace them with the notice
  36.  * and other provisions required by the GPL or the LGPL. If you do not delete
  37.  * the provisions above, a recipient may use your version of this file under
  38.  * the terms of any one of the MPL, the GPL or the LGPL.
  39.  *
  40.  * ***** END LICENSE BLOCK ***** */
  41.  
  42. const kCalRecurrenceInfoContractID = "@mozilla.org/calendar/recurrence-info;1";
  43. const kCalIRecurrenceInfo = Components.interfaces.calIRecurrenceInfo;
  44.  
  45. const kCalRecurrenceRuleContractID = "@mozilla.org/calendar/recurrence-rule;1";
  46. const kCalIRecurrenceRule = Components.interfaces.calIRecurrenceRule;
  47.  
  48. const kCalRecurrenceDateSetContractID = "@mozilla.org/calendar/recurrence-date-set;1";
  49. const kCalIRecurrenceDateSet = Components.interfaces.calIRecurrenceDateSet;
  50.  
  51. const kCalRecurrenceDateContractID = "@mozilla.org/calendar/recurrence-date;1";
  52. const kCalIRecurrenceDate = Components.interfaces.calIRecurrenceDate;
  53.  
  54. /* Constructor helpers, lazily initialized to avoid registration races. */
  55. var CalRecurrenceInfo = null;
  56. var CalRecurrenceRule = null;
  57. var CalRecurrenceDateSet = null;
  58. var CalRecurrenceDate = null;
  59. var CalDateTime = null;
  60. var CalDuration = null;
  61. var CalAttendee = null;
  62. var CalItipItem = null;
  63.  
  64. var componentInitRun = false;
  65. function initBaseComponent()
  66. {
  67.     CalRecurrenceInfo = new Components.Constructor(kCalRecurrenceInfoContractID, kCalIRecurrenceInfo);
  68.     CalRecurrenceRule = new Components.Constructor(kCalRecurrenceRuleContractID, kCalIRecurrenceRule);
  69.     CalRecurrenceDateSet = new Components.Constructor(kCalRecurrenceDateSetContractID, kCalIRecurrenceDateSet);
  70.     CalRecurrenceDate = new Components.Constructor(kCalRecurrenceDateContractID, kCalIRecurrenceDate);
  71.  
  72.     CalDateTime = new Components.Constructor("@mozilla.org/calendar/datetime;1",
  73.                                              Components.interfaces.calIDateTime);
  74.     CalDuration = new Components.Constructor("@mozilla.org/calendar/duration;1",
  75.                                              Components.interfaces.calIDateTime);
  76.     CalAttendee = new Components.Constructor("@mozilla.org/calendar/attendee;1",
  77.                                              Components.interfaces.calIAttendee);
  78.     CalItipItem = new Components.Constructor("@mozilla.org/calendar/itip-item;1",
  79.                                              Components.interfaces.calIItipItem);
  80. }
  81.  
  82.  
  83. /* Update these in calBaseCID.h */
  84. const componentData =
  85.     [
  86.      /* calItemBase and calUtils must be first: later scripts depend on them */
  87.     {cid: null,
  88.      contractid: null,
  89.      script: "calItemBase.js",
  90.      constructor: null},
  91.  
  92.     {cid: null,
  93.      contractid: null,
  94.      script: "calUtils.js",
  95.      constructor: null},
  96.  
  97.     {cid: Components.ID("{f42585e7-e736-4600-985d-9624c1c51992}"),
  98.      contractid: "@mozilla.org/calendar/manager;1",
  99.      script: "calCalendarManager.js",
  100.      constructor: "calCalendarManager",
  101.      onComponentLoad: "onCalCalendarManagerLoad()"},
  102.  
  103.     {cid: Components.ID("{7a9200dd-6a64-4fff-a798-c5802186e2cc}"),
  104.      contractid: "@mozilla.org/calendar/alarm-service;1",
  105.      script: "calAlarmService.js",
  106.      constructor: "calAlarmService",
  107.      service: true},
  108.  
  109.     {cid: Components.ID("{974339d5-ab86-4491-aaaf-2b2ca177c12b}"),
  110.      contractid: "@mozilla.org/calendar/event;1",
  111.      script: "calEvent.js",
  112.      constructor: "calEvent"},
  113.  
  114.     {cid: Components.ID("{7af51168-6abe-4a31-984d-6f8a3989212d}"),
  115.      contractid: "@mozilla.org/calendar/todo;1",
  116.      script: "calTodo.js",
  117.      constructor: "calTodo"},
  118.  
  119.     {cid: Components.ID("{5c8dcaa3-170c-4a73-8142-d531156f664d}"),
  120.      contractid: "@mozilla.org/calendar/attendee;1",
  121.      script: "calAttendee.js",
  122.      constructor: "calAttendee"},
  123.  
  124.     {cid: Components.ID("{5f76b352-ab75-4c2b-82c9-9206dbbf8571}"),
  125.      contractid: "@mozilla.org/calendar/attachment;1",
  126.      script: "calAttachment.js",
  127.      constructor: "calAttachment"},
  128.  
  129.     {cid: Components.ID("{04027036-5884-4a30-b4af-f2cad79f6edf}"),
  130.      contractid: "@mozilla.org/calendar/recurrence-info;1",
  131.      script: "calRecurrenceInfo.js",
  132.      constructor: "calRecurrenceInfo"},
  133.  
  134.     {cid: Components.ID("{4123da9a-f047-42da-a7d0-cc4175b9f36a}"),
  135.      contractid: "@mozilla.org/calendar/datetime-formatter;1",
  136.      script: "calDateTimeFormatter.js",
  137.      constructor: "calDateTimeFormatter"},
  138.  
  139.     {cid: Components.ID("{6877bbdd-f336-46f5-98ce-fe86d0285cc1}"),
  140.      contractid: "@mozilla.org/calendar/weektitle-service;1",
  141.      script: "calWeekTitleService.js",
  142.      constructor: "calWeekTitleService"},
  143.  
  144.     {cid: Components.ID("{f41392ab-dcad-4bad-818f-b3d1631c4d93}"),
  145.      contractid: "@mozilla.org/calendar/itip-item;1",
  146.      script: "calItipItem.js",
  147.      constructor: "calItipItem"},
  148.  
  149.     {cid: Components.ID("{9787876b-0780-4464-8282-b7f86fb221e8}"),
  150.      contractid: "@mozilla.org/calendar/itip-processor;1",
  151.      script: "calItipProcessor.js",
  152.      constructor: "calItipProcessor"},
  153.  
  154.     {cid: Components.ID("{1e2fc0e2-bf5f-4d60-9f1e-5e92cf517c0b}"),
  155.      contractid: "@mozilla.org/network/protocol;1?name=webcal",
  156.      script: "calProtocolHandler.js",
  157.      constructor: "calProtocolHandler"},
  158.  
  159.     {cid: Components.ID("{6fe88047-75b6-4874-80e8-5f5800f14984}"),
  160.      contractid: "@mozilla.org/calendar/ics-parser;1",
  161.      script: "calIcsParser.js",
  162.      constructor: "calIcsParser"},
  163.  
  164.     {cid: Components.ID("{207a6682-8ff1-4203-9160-729ec28c8766}"),
  165.      contractid: "@mozilla.org/calendar/ics-serializer;1",
  166.      script: "calIcsSerializer.js",
  167.      constructor: "calIcsSerializer"},
  168.  
  169.     {cid: Components.ID("{40a1ccf4-5f54-4815-b842-abf06f84dbfd}"),
  170.      contractid: "@mozilla.org/calendar/transactionmanager;1",
  171.      script: "calTransactionManager.js",
  172.      constructor: "calTransactionManager"}
  173.     ];
  174.  
  175. var calItemModule = {
  176.     mScriptsLoaded: false,
  177.     loadScripts: function () {
  178.         if (this.mScriptsLoaded)
  179.             return;
  180.  
  181.         const jssslContractID = "@mozilla.org/moz/jssubscript-loader;1";
  182.         const jssslIID = Components.interfaces.mozIJSSubScriptLoader;
  183.  
  184.         const dirsvcContractID = "@mozilla.org/file/directory_service;1";
  185.         const propsIID = Components.interfaces.nsIProperties;
  186.  
  187.         const iosvcContractID = "@mozilla.org/network/io-service;1";
  188.         const iosvcIID = Components.interfaces.nsIIOService;
  189.  
  190.         var loader = Components.classes[jssslContractID].getService(jssslIID);
  191.         var dirsvc = Components.classes[dirsvcContractID].getService(propsIID);
  192.         var iosvc = Components.classes[iosvcContractID].getService(iosvcIID);
  193.  
  194.         // Note that unintuitively, __LOCATION__.parent == .
  195.         // We expect to find the subscripts in ./../js
  196.         var appdir = __LOCATION__.parent.parent;
  197.         appdir.append("js");
  198.  
  199.         for (var i = 0; i < componentData.length; i++) {
  200.             var scriptName = componentData[i].script;
  201.             if (!scriptName)
  202.                 continue;
  203.  
  204.             var f = appdir.clone();
  205.             f.append(scriptName);
  206.  
  207.             try {
  208.                 var fileurl = iosvc.newFileURI(f);
  209.                 loader.loadSubScript(fileurl.spec, null);
  210.             } catch (e) {
  211.                 dump("Error while loading " + fileurl.spec + "\n");
  212.                 throw e;
  213.             }
  214.         }
  215.  
  216.         this.mScriptsLoaded = true;
  217.     },
  218.  
  219.     registerSelf: function (compMgr, fileSpec, location, type) {
  220.         compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
  221.  
  222.         var catman = Components.classes["@mozilla.org/categorymanager;1"]
  223.             .getService(Components.interfaces.nsICategoryManager);
  224.         for (var i = 0; i < componentData.length; i++) {
  225.             var comp = componentData[i];
  226.             if (!comp.cid)
  227.                 continue;
  228.             compMgr.registerFactoryLocation(comp.cid,
  229.                                             "",
  230.                                             comp.contractid,
  231.                                             fileSpec,
  232.                                             location,
  233.                                             type);
  234.  
  235.             if (comp.category) {
  236.                 var contractid;
  237.                 if (comp.service)
  238.                     contractid = "service," + comp.contractid;
  239.                 else
  240.                     contractid = comp.contractid;
  241.                 catman.addCategoryEntry(comp.category, comp.categoryEntry,
  242.                                         contractid, true, true);
  243.             }
  244.         }
  245.     },
  246.  
  247.     makeFactoryFor: function(constructor) {
  248.         var factory = {
  249.             QueryInterface: function (aIID) {
  250.                 if (!aIID.equals(Components.interfaces.nsISupports) &&
  251.                     !aIID.equals(Components.interfaces.nsIFactory))
  252.                     throw Components.results.NS_ERROR_NO_INTERFACE;
  253.                 return this;
  254.             },
  255.  
  256.             createInstance: function (outer, iid) {
  257.                 if (outer != null)
  258.                     throw Components.results.NS_ERROR_NO_AGGREGATION;
  259.                 return (new constructor()).QueryInterface(iid);
  260.             }
  261.         };
  262.  
  263.         return factory;
  264.     },
  265.  
  266.     getClassObject: function (compMgr, cid, iid) {
  267.         if (!iid.equals(Components.interfaces.nsIFactory))
  268.             throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
  269.  
  270.         if (!this.mScriptsLoaded)
  271.             this.loadScripts();
  272.  
  273.         if (!componentInitRun) {
  274.             initBaseComponent();
  275.             componentInitRun = true;
  276.         }
  277.  
  278.         for (var i = 0; i < componentData.length; i++) {
  279.             if (cid.equals(componentData[i].cid)) {
  280.                 if (componentData[i].onComponentLoad) {
  281.                     eval(componentData[i].onComponentLoad);
  282.                 }
  283.                 // eval to get usual scope-walking
  284.                 return this.makeFactoryFor(eval(componentData[i].constructor));
  285.             }
  286.         }
  287.  
  288.         throw Components.results.NS_ERROR_NO_INTERFACE;
  289.     },
  290.  
  291.     canUnload: function(compMgr) {
  292.         return true;
  293.     }
  294. };
  295.  
  296. function NSGetModule(compMgr, fileSpec) {
  297.     return calItemModule;
  298. }
  299.